package com.dckxx.common.constant;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ck
 */

public enum CommonEnum {

    SEX_1("sex","1", "男"),
    SEX_2("sex","2","女"),
    YES("deleted","1","是"),
    NO("deleted","0","否");

    private String type;
    private String key;
    private String value;

    CommonEnum(String type,String key, String value) {
        this.type = type;
        this.key = key;
        this.value = value;
    }

    public static Map<String, Map<String,String>> getMapList(){
        Map<String, Map<String,String>> resultMap = new HashMap<>();
        Map<String, String> map = new HashMap<>();

        String tempType = "";
        int tempLen = 0;
        for (CommonEnum e : CommonEnum.values()) {
            tempLen += 1;
            int len = CommonEnum.values().length;
            String type = e.type;
            if(StringUtils.isNotEmpty(tempType) && (!type.equals(tempType) || tempLen == len)){
                if(tempLen == len){
                    map.put(e.key, e.value);
                }
                resultMap.put(tempType, map);
                map = new HashMap<>();
            }
            map.put(e.key, e.value);
            tempType = type;
        }
        return resultMap;
    }

}
